package com.whj.wkpt.mapper;

import com.whj.wkpt.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    
    User findById(Long userId);
    
    User findByUsername(String username);
    
    User findByEmail(String email);
    
    boolean existsByUsername(String username);
    
    boolean existsByEmail(String email);
    
    @Insert("INSERT INTO users(username, password, email, phone, role, create_time, update_time) " +
            "VALUES(#{username}, #{password}, #{email}, #{phone}, #{role}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "userId")
    int insert(User user);
    
    @Update("UPDATE users SET username=#{username}, password=#{password}, email=#{email}, " +
            "phone=#{phone}, role=#{role}, update_time=#{updateTime} WHERE user_id=#{userId}")
    int update(User user);
    
    @Delete("DELETE FROM users WHERE user_id = #{userId}")
    int deleteById(Long userId);
    
    List<User> findAll();
    
    List<User> findByIds(List<Long> userIds);
}